<template>
  <div class="saying-write_page">
       <Form ref="formInline" :model="formItem" :rules="ruleInline">
         <FormItem label="语录" prop="saying">
            <Input v-model="formItem.saying" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="Enter something...（限长200）"></Input>
        </FormItem>
        <FormItem>
            <Button type="primary"  :loading="loading" @click="handleSubmit('formInline')">Signin</Button>
        </FormItem>
    </Form>
  </div>
</template>

<script>
export default {
  data(){
    return {
        formItem: {
              saying: ''
        },
        ruleInline: {
            saying: [
                { required: true, message: '请按要求填写语录',max:200, trigger: 'blur' }
            ],
          
        },
        loading:false
            }
  }, 
  methods: {
            handleSubmit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                         const that = this
                         that.loading = true;
                         this.$axios.post('/api/manage/saying/save',this.formItem).then(res =>{
                           that.loading = false;
                            if(res.data.err_code == 0){
                              that.$router.push('/login')
                            }else if(res.data.err_code == 1){
                              that.$Message.error('没查询到用户！')
                            }else if(res.data.err_code == 2){
                              that.$Message.error('权限不足！')
                            }else if(res.data.err_code == 3){
                              that.$refs.formInline.resetFields();
                              that.$Message.success('语录发布成功！')
                            }else{
                              that.$Message.error('服务器出错！')
                            }
                          })
                    } else {
                        this.$Message.error('Fail!');
                    }
                })
            }
        },
  
}
</script>

<style>

</style>